package com.socialmediaanalytics.client.facebook;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.socialmediaanalytics.client.facebook.sdk.FBCore;
import com.socialmediaanalytics.client.facebook.sdk.FBEvent;

/**
 * 
 * @Architecture
 */
public class FacebookAuthentication {

	// public static String APPID = "158550007562379"; // localhost

	public static String APPID = "213506215378062";

	private FBCore fbCore = GWT.create(FBCore.class);
	private FBEvent fbEvent = GWT.create(FBEvent.class);

	private boolean status = true;
	private boolean xfbml = true;
	private boolean cookie = true;

	public FacebookAuthentication() {

		fbCore.init(APPID, status, cookie, xfbml);

		if (fbCore.getSession() != null) {

			new FacebookAboutMe(fbCore);

			new FacebookFriends(fbCore);
		}

		fbEvent.subscribe("auth.sessionChange",
				new AsyncCallback<JavaScriptObject>() {

					@Override
					public void onFailure(Throwable caught) {

					}

					@Override
					public void onSuccess(JavaScriptObject result) {

						new FacebookAuthentication();
					}
				});
	}
}
